package com.jizhi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jizhi.entity.Caigou;
import com.jizhi.entity.Drugstore;
import com.jizhi.mapper.CaigouMapper;
import com.jizhi.service.CaigouService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 王书豪
 * @since 2020-11-18
 */
@Service
public class CaigouServiceImpl extends ServiceImpl<CaigouMapper, Caigou> implements CaigouService {
    @Resource
    private CaigouMapper caigouMapper;
    @Override
    public int updateCaigou(Caigou caigou) {
        QueryWrapper<Caigou> wrapper=new QueryWrapper<>();
        wrapper.eq("caigouname",caigou.getCaigouname());
        //根据采购单药品名字查询是否已有采购单
        Caigou caigou1= caigouMapper.selectOne(wrapper);
        int num=0;
        if (null!=caigou1){
            //如果有就通过id修改采购单表
            caigou.setCaigouid(caigou1.getCaigouid());
            num= caigouMapper.updateById(caigou);
        }else {
            //如果没有就添加采购单
            num= caigouMapper.insert(caigou);
        }
        return num;
    }
}
